package com.welsmann.app.start.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.mysql.jdbc.StringUtils;
import com.welsmann.app.start.entity.Site;

@Controller
public class SiteController extends BaseController {

	@RequestMapping("/visit/{alias}")
	public ModelAndView redirect(@PathVariable String alias) {
		ModelAndView mav = new ModelAndView("redirect:/index.html");
		if (!StringUtils.isEmptyOrWhitespaceOnly(alias)) {
			Site site = super.siteService.clickByAlias(alias);
			if (site != null
					&& !StringUtils.isEmptyOrWhitespaceOnly(site.getUrl())) {
				mav.setViewName("redirect:" + site.getUrl());
			}
		} 
		return mav;
	}
}
